package com.zyd.shiro.controller.admin;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zyd.shiro.persistence.beans.DeliveryRule;
import com.zyd.shiro.business.service.MallDeliveryRuleService;

import com.zyd.shiro.framework.object.PageResult;
import com.zyd.shiro.framework.object.ResponseVO;
import com.zyd.shiro.util.ResultUtil;
/**
 * 控制器层
 * @author RookieWZW
 *
 */
@RestController
@CrossOrigin
@RequestMapping("/deliveryRule")
public class DeliveryRuleController {

	@Autowired
	private MallDeliveryRuleService deliveryRuleService;
	
	/**
	 * 查询全部数据
	 * @return
	 */
	@RequestMapping(value="/",method=RequestMethod.GET)
	public ResponseVO findAll(){
		 return ResultUtil.success("查询成功",deliveryRuleService.findAll());
		
	}
	
	/**
	 * 根据ID查询
	 * @param id ID
	 * @return
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public ResponseVO findOne(@PathVariable Integer id){
		return ResultUtil.success("查询成功", deliveryRuleService.findOne(id));	
		
	}
	
	/**
	 * 分页查询全部数据
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/{page}/{size}",method=RequestMethod.GET)
	public ResponseVO findPage(@PathVariable int page,@PathVariable int size){		
		Page<DeliveryRule> pageList = deliveryRuleService.findPage(page, size);		
		return ResultUtil.success("查询成功",new PageResult(pageList.getTotalElements(), pageList.getContent() ) );	
	}
	
	/**
	 * 分页+多条件查询 
	 * @param searchMap 查询条件封装
	 * @param page 页码
	 * @param size 页大小
	 * @return 分页结果
	 */
	@RequestMapping(value="/{page}/{size}",method=RequestMethod.POST)
	public ResponseVO findSearch(@RequestBody Map searchMap ,@PathVariable int page,@PathVariable int size){		
		Page<DeliveryRule> pageList = deliveryRuleService.findSearch(searchMap, page, size);
		return ResultUtil.success("查询成功",  new PageResult(pageList.getTotalElements(), pageList.getContent()) );		
	}
	
	/**
	 * 增加
	 * @param deliveryRule
	 */
	@RequestMapping(value="/",method=RequestMethod.POST)
	public ResponseVO add(@RequestBody DeliveryRule deliveryRule  ){
		deliveryRuleService.add(deliveryRule);			
		return ResultUtil.success("增加成功");
	}
	
	/**
	 * 修改
	 * @param deliveryRule
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.PUT)
	public ResponseVO update(@RequestBody DeliveryRule deliveryRule,@PathVariable Integer id ){
		deliveryRule.setId(id);
		deliveryRuleService.update(deliveryRule);		
		return ResultUtil.success("修改成功");
	}
	
	/**
	 * 删除
	 * @param id
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.DELETE)
	public ResponseVO delete(@PathVariable Integer id ){
		deliveryRuleService.delete(id);
		return ResultUtil.success("删除成功");
	}
	
}
